﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Collections.Specialized;
using PreeRegisterModel;
using PreeRegisterBLL;
using PreeRegisterBLL.Security;

namespace PreeRegister_WebAPI.Controllers
{
    public class PacsController : ApiController
    {
        [HttpPost]
        /// <summary>
        /// 查询检查报告
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel report(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                PacsReportListResponseModel PacsReportListResponseModel = new PacsReportListResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "pacs|report", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.PacsReportListResponseModel(PacsReportListResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("pacs|report|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                PacsReportListRequestModel PacsReportListRequestModel = csSerialize.PacsReportListRequestModel(body_json);

                //查询检查报告列表
                PacsReportListResponseModel = PacsReportBLL.GetPacsReportList(PacsReportListRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.PacsReportListResponseModel(PacsReportListResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("Pacs|report|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                PacsReportListResponseModel PacsReportListResponseModel = new PacsReportListResponseModel();

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.PacsReportListResponseModel(PacsReportListResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("pacs|report|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }


        [HttpPost]
        /// <summary>
        /// 查询检查报告明细
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel detail(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                PacsReportDetailResponseModel PacsReportDetailResponseModel = new PacsReportDetailResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "pacs|detail", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.PacsReportDetailResponseModel(PacsReportDetailResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("pacs|detail|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                PacsReportDetailRequestModel PacsReportDetailRequestModel = csSerialize.PacsReportDetailRequestModel(body_json);

                //查询检验报告列表
                PacsReportDetailResponseModel = PacsReportBLL.GetPacsReportDetail(PacsReportDetailRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.PacsReportDetailResponseModel(PacsReportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("pacs|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                PacsReportDetailResponseModel PacsReportDetailResponseModel = new PacsReportDetailResponseModel();

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.PacsReportDetailResponseModel(PacsReportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("pacs|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }
    }
}